package adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import entity.CipaiInfo;

import com.example.administrator.ci_edit.R;

/**
 * Created by hello world on 2017/7/13.
 */

public class CipaiInfoAdapter extends ArrayAdapter<CipaiInfo> {
    private int resourceId;
    public CipaiInfoAdapter(Context context, int textViewResourceId, List<CipaiInfo> objects){
        super(context,textViewResourceId,objects);
        resourceId=textViewResourceId;
    }
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        CipaiInfo cipaiInfo=getItem(position);
        //View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
        //用新的方式，提升ListView的运行效率
        View view;
        if(convertView==null){
            view=LayoutInflater.from(getContext()).inflate(resourceId,null);
        }else{
            view=convertView;
        }
        //ImageView cipaiImage=(ImageView)view.findViewById(R.id.cipai_image);
        TextView cipaiName=(TextView)view.findViewById(R.id.cipai_name);
        //cipaiImage.setImageResource(cipaiInfo.getImageId());
        cipaiName.setText(cipaiInfo.getName());
        return view;
        //return super.getView(position, convertView, parent);
    }
}
